function quickSort(arr) {
    if (arr.length <= 1) {
        return arr;
    }
    const right = [];
    const left = [];
    const pivot = arr.shift();
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] < pivot) {
            left.push(arr[i]);
        } else {
            right.push(arr[i]);
        }
    }
    return [...quickSort(left), pivot, ...quickSort(right)];
}

const arr = [5, 2, 7, 1, 9, 3, 8, 4, 6];
console.log(quickSort(arr))
